Skip to content

Conversation

@mattt
Copy link
Owner

@mattt mattt commented Dec 11, 2025

Related to #27

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements guided generation for SystemLanguageModel, enabling structured output generation using schema-based constraints. The implementation adds support for generating strongly-typed Swift structs from natural language prompts by converting GenerationSchema to FoundationModels' schema format and handling both streaming and non-streaming responses.

Key Changes:

  • Added schema-based generation support for non-String types using FoundationModels' schema APIs with proper $defs dependency extraction
  • Implemented partial JSON decoding with fallback to placeholder content for graceful error recovery
  • Refactored ResponseStream to use fallbackSnapshot pattern instead of storing concrete content values

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
Sources/AnyLanguageModel/Models/SystemLanguageModel.swift Core implementation of guided generation with schema conversion, streaming support, and placeholder fallback logic
Tests/AnyLanguageModelTests/SystemLanguageModelTests.swift Comprehensive test suite covering simple structs, nested structures, arrays, enum constraints, and streaming
Sources/AnyLanguageModel/LanguageModelSession.swift Refactored ResponseStream to use optional fallbackSnapshot for cleaner handling of streaming vs non-streaming cases
Sources/AnyLanguageModel/GenerationSchema.swift Made defs property accessible to support schema resolution in SystemLanguageModel
Sources/AnyLanguageModel/Generable.swift Enhanced asPartiallyGenerated() with safer conversion logic and fallback to generatedContent reconstruction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mattt mattt force-pushed the mattt/system-guided-generation branch from 1fa983e to 679e9d0 Compare January 20, 2026 12:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mattt mattt merged commit a0107a9 into main Jan 20, 2026
3 checks passed
@mattt mattt deleted the mattt/system-guided-generation branch January 20, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants